//
//  BIndexViewController.m
//  penzer
//
//  Created by caiyc on 2018/10/6.
//  Copyright © 2018年 caiyc. All rights reserved.
//

#import "BIndexViewController.h"
#import "B_WaithandelViewController.h"
#import "B_moneyViewController.h"
#import "BloginViewController.h"
#import "StaticCenterViewController.h"
@interface BIndexViewController ()
@property(assign)NSInteger now_In_Tab;

@end

@implementation BIndexViewController
-(void)viewWillAppear:(BOOL)animated{
    if(![XTool GetDefaultInfo:BUSSION_INFO]){
        [WToast showWithText:@"请登录"];
        BloginViewController *vc = [[BloginViewController alloc]init];
        [self pushSecondVC:vc];
    }else{
        if(self.botom_scroView){
            [self.botom_scroView setContentOffset:CGPointMake(screen_width*self.now_In_Tab, 0) animated:0];
        }
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.now_In_Tab=0;
    [self setContent];
 
    // Do any additional setup after loading the view from its nib.
}
-(void)setContent{
    UIButton *btn_1 = (UIButton *)[self.view viewWithTag:1024];
    btn_1.selected = 1;
    CGFloat contetn_height = self.botom_scroView.frame.size.height;
CGFloat contete_width =  self.botom_scroView.frame.size.width;
    B_WaithandelViewController *vc1 = [[B_WaithandelViewController alloc]init];
    vc1.view.frame = CGRectMake(0, 0, contete_width, contetn_height);
    [self.botom_scroView addSubview:vc1.view];
    [self addChildViewController:vc1];
    B_moneyViewController *vc2 = [[B_moneyViewController alloc]init];
    vc2.view.frame = CGRectMake(screen_width*1, 0, contete_width, contetn_height);
    [self.botom_scroView addSubview:vc2.view];
    [self addChildViewController:vc2];
    self.botom_scroView.scrollEnabled = 0;
    StaticCenterViewController *vc3 = [[StaticCenterViewController alloc]init];
    vc3.view.frame = CGRectMake(screen_width*2, 0, contete_width, contetn_height);
    [self.botom_scroView addSubview:vc3.view];
    [self addChildViewController:vc3];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)tabIndex:(UIButton *)sender {
    sender.selected = !sender.selected;
    UIButton *btn_1 = (UIButton *)[self.view viewWithTag:1024];
    UIButton *btn_2 = (UIButton *)[self.view viewWithTag:1025];
    UIButton *btn_3 = (UIButton *)[self.view viewWithTag:1026];
    if(sender.tag==1024){
        btn_2.selected = 0;
        btn_3.selected = 0;
        
    }else if (sender.tag==1025){
        btn_3.selected = 0;
        btn_1.selected = 0;
    }else{
        btn_1.selected = 0;
        btn_2.selected = 0;
    }
    NSInteger index = sender.tag-1024;
    self.now_In_Tab = index;
    [self.botom_scroView setContentOffset:CGPointMake(screen_width*index, 0) animated:0];
}
@end
